﻿<?php include $this -> admin_tpl("header"); ?>
    <!-- 内容区 -->
      <style>
    #Validform_msg {
    display: none
    }
    img {
        cursor: pointer;
    }
    .editor .ke-toolbar span,
    .editor .ke-statusbar span {
        padding: 0px;
    }
    .editor .ke-toolbar .ke-outline {
        border: 1px solid #F0F0EE;
        cursor: pointer;
        display: block;
        float: left;
        font-size: 0;
        line-height: 0;
        margin: 1px;
        overflow: hidden;
        padding: 1px 2px;
    }
    .imgWrap div {
        border: 1px solid #3B72A5;
        cursor: pointer;
        float: left;
        margin-left: 26px;
        margin-top: 20px;
        position: relative;
    }
    .imgWrap div span {
        color: #FFFFFF;
        display: none;
        padding: 0 5px;
        position: absolute;
    }
    .setdef {
        background: none repeat scroll 0 0 #F48C3A;
        bottom: 0;
        line-height: 18px;
        height: 18px;
        position: absolute;
        right: 0;
        padding: 0 5px;
        display: none;
        z-index: 9999;
        color: #FFFFFF;
    }
    .setdel:hover{
        color: #E4F14A;
    }
    .setdel {
        cursor:pointer;
        background: none repeat scroll 0 0 #3b72a5;
        top: 200;
        color: #FFFFFF;
        display: none;
        height: 18px;
        line-height: 18px;
        padding: 0 5px;
        position: absolute;
        right: 0px;
        z-index: 9999;
    }
    table.areaBox th {
        background: #e8f5fc;
        border-bottom: 1px solid #e8f5fc;
    }
    table.areaBox {
        border-left: 1px solid #e8f5fc;
        border-right: 1px solid #e8f5fc;
        border-top: 1px solid #e8f5fc;
        margin: 10px auto;
        width: 720px;
    }
    table.areaBox td {
        border-bottom: 1px solid #e8f5fc;
    }
    .add_area,
    table.areaBox {
    width: 98%;
}</style>
    <div class="content">
        <div class="site">
            <?php echo C('site_name')?> <a href="#">商品管理</a> >
            <?php if($_list['id']):?>
                编辑商品
            <?php else:?>
                添加商品
            <?php endif;?>
        </div>
        <span class="line_white"></span>
    <div class="install tabs mt10">
        <dl>
            <!-- <dt><a href="javascript:" class="hover">基本信息</a><a href="javascript:">商品规格</a><a href="javascript:">商品属性</a><a href="javascript:">详细描述</a><a href="javascript:">商品图册</a></dt> -->
            <dt><a href="javascript:" class="hover">基本信息</a></dt>
            <form method="post" action="<?php echo $posturl; ?>" name="goodsForm" class="goodsForm" onsubmit="return checkForm()">
                <dd>
                    <ul class="web">
                        <li>
                            <strong>商品名称：</strong>
                            <input type="text" value="<?php echo $_list['name']; ?>" class="text_input" datatype="*" nullmsg="请输入商品名称！" name="name"  /><span>填写商品名称</span>
                        </li>
                  
                        <li>
                            <strong>所属分类：</strong>
                             <select name="cat_ids" class="select" style="margin-right: 48px;" <?php if(isset($if_upd) && $if_upd)  : ?>disabled="disabled" <?php else : ?> <?php endif ?>>
                                <option value="0">请选择</option>
                                <?php foreach ($category as $key => $value): ?>
                                    <option value="<?php echo $value['id']; ?>"
                                        <?php if( $value['if_selected'] == 1) : ?> selected = "selected"
                                        <?php else : ?> 
                                       
                                        <?php endif ?>>
                                        <?php echo $value['name']; ?>
                                    </option>
                                <?php endforeach ?>
                            </select><span>商品所属分类</span>
                        </li>
                        <li>
                            <strong>商品价格</strong>
                            <input type="text" value="<?php echo $_list['price']; ?>" class="text_input" datatype="*" nullmsg="请输入商品名称！" name="price"  /><span>GF</span>
                        </li>

                        <li>
                            <strong>是否上架销售：</strong>
                            <b style="margin-right: 44px;">
                                <label><input type="radio" name="status" value="1" <?php if (isset($_list['status']) && $_list['status'] == 1): ?>
                                    checked
                                <?php else: ?>
                                    checked
                                <?php endif ?>/> 是 </label>
                                <label><input type="radio" name="status" value="0" <?php if (isset($_list['status']) && $_list['status'] == 0): ?>
                                    checked
                                <?php endif ?>/> 否 </label>
                            </b>
                            <span style="margin-left:1px">设置当前商品是否上架销售，默认为是，如选择否，将不在前台显示该商品</span>
                        </li>
                       
                        <li>
                            <strong>排序：</strong>
                            <input type="text" class="text_input" name="sort" placeholder=''  datatype="n" value="<?php echo $_list['sort']?$_list['sort']:100?>" /><span class="Validform_checktip">输入数字显示排序，数字越小越靠前数字越大越靠后</span>
                        </li>
                        <li>
                            <strong>商品关键词：</strong>
                            <input type="text" value="<?php echo $_list['keyword']; ?>" name="keyword" class="text_input" /><span style="margin-left:-2px">用于在前台、后台筛选商品，多个关键词用空格分开，同时作为商品的Meta Keyword，有利于搜索引擎优化</span>
                        </li>
                        <li>
                            <strong>商品描述：</strong>
                            <textarea name="brief" style="margin-right: 52px;" class="textarea">
<?php echo $_list['brief']; ?></textarea><p class="p">为商品编辑内容描述，同时作为商品的Meta Description，有利于搜索引擎优化</p>
                        </li>
                    </ul>
                </dd>



              
                <!-- <dd>
                   <div class="edit_box">
                       <strong class="edit">您正在编辑当前商品详细信息，默认所见即所得模式，您也可以点击HTML源码切换到代码模式进行编辑。</strong>
                       <div class="editor edit"><?php echo form::editor('content', $_list['descript']);?></div>
                   </div>
                </dd>
                <dd>
                   <?php   if (empty($_list['pics'])): ?>
                       <div id="wrapper">
                           <div id="container"> -->
            <!--头部，相册选择和格式选择-->
                              <!-- <div id="uploader">
                               <div class="queueList">
                                   <div id="dndArea" class="placeholder">
                                      <div id="filePicker"></div>
                                      </div>
                                   <ul class="filelist"></ul>
                               </div>
                             <div class="statusBar" style="display:none">
                               <div class="progress">
                                    <span class="text">0%</span>
                                    <span class="percentage"></span>
                               </div>
                                    <div class="info"></div>
                               <div class="btns">
                                 <div id="filePicker2" class="webuploader-containe webuploader-container"></div><div class="uploadBtn state-finish">开始上传</div>
                               </div>
                            </div>
                         </div>
                      </div>
                   </div>
                 <?php else:?>
                    <div id="wrapper">
                       <div id="container">
                          <div id="uploader">
                             <div class="queueList">
                                 <div id="dndArea" class="placeholder element-invisible">
                                    <div id="filePicker" class="webuploader-container"></div>
                                    </div>
                                 <ul class="filelist"></ul>
                            </div>
                            <div class="statusBar" style="">
                               <div class="progress">
                                    <span class="text"></span>
                                    <span class="percentage"></span>
                               </div>
                               <div class="info"></div>
                               <div class="btns">
                                  <div id="filePicker2" class="webuploader-containe webuploader-container"></div>
                                  <div class="uploadBtn state-finish">开始上传</div>
                               </div>
                            </div>
                        </div>
                    </div>
                 </div>
             <?php endif?> -->
    <link rel="stylesheet" type="text/css" href="<?php echo CSS_PATH; ?>style.css" />
    <link rel="stylesheet" type="text/css" href="<?php echo CSS_PATH; ?>webuploader.css" />
    <script type="text/javascript" src="<?php echo JS_PATH;?>image-upload/webuploader.js"></script>
    <script type="text/javascript" src="<?php echo JS_PATH;?>image-upload/upload.js"></script>
                </dd>
                <div class="submit">
                    <?php if($_list['id']):?>
                    <input type="hidden" name="id" value="<?php echo $_list['id']; ?>" />
                    <?php endif;?>
                    <input type="submit" class='button_search' value='提交'/>
                    <?php if($_SERVER['REQUEST_URI'] != U('goods/goods/add')):?>
                      <a href="<?php echo U('lists')?>">返回</a>
                    <?php endif;?>
                </div>
                <!-- <input type="hidden" name="del_products_all" value="no"> -->
            </form>
        </dl>
    </div>
    <!--批量编辑商品信息弹窗-->
<!-- <div id="batcheditGoods" class="BatchEditingMoney">
    <ul>
        <li class="w85"><strong>库存</strong></li>
        <li class="w85"><strong>销售价格</strong></li>
        <li class="w85"><strong>市场价格</strong></li>
        <li class="w85"><strong>成本价格</strong></li>
    </ul>
    <ul>
        <li class="w85"><input type="text" name="_goods_number_change" value="+0" /></li>
        <li class="w85"><input type="text" name="_shop_price_change" value="+0.00" /></li>
        <li class="w85"><input type="text" name="_market_price_change" value="+0.00" /></li>
        <li class="w85"><input type="text" name="_cost_price_change" value="+0.00" /></li>
    </ul>
    <p>小提示：此处修改的值将对所有商品值进行加减修改如:+10 -5<br>库存必须是整数  价格可带两位小数</p>
</div> -->
    <?php include $this->admin_tpl('copyright'); ?>
    <!--选择框-->
    <script src="<?php echo JS_PATH; ?>jquery.goods_add_category.js"></script>
    <!--模板-->
    <script type="text/javascript" src="<?php echo JS_PATH; ?>artTemplate/artTemplate.js"></script>
    <script type="text/javascript" src="<?php echo JS_PATH; ?>artTemplate/artTemplate-plugin.js"></script>
    <!--编辑器开始-->
    <script type="text/javascript" src="<?php echo JS_PATH; ?>admin/goods_pics.js"></script>
    <script type="text/javascript" src="<?php echo JS_PATH; ?>admin/goods_cat.js"></script>
    <script type="text/javascript" src="<?php echo JS_PATH; ?>admin/goods_spec.js"></script>
    <script type="text/javascript" src="<?php echo JS_PATH; ?>admin/goods_model.js"></script>
    <script src="/statics/js/layer/layer.js"></script>
    <script>

        function checkForm(){
            var type = "<?php echo $posturl; ?>";
            var name = $("input[name='name']").val();
          
            var category_id =  $(".select ").val();
           
            var price = $("input[name='price']").val();
         
            var status = $("input[name='status']").val();
           
            var sort = $("input[name='sort']").val();
          
            var keyword = $("input[name='keyword']").val();
           
            var brief = $(".textarea").val();
           
            var id = $("input[name='id']").val();
           
            if(!name || category_id == '0' || !price || !keyword || !brief){
                layer.msg('请填写提交的信息');
                return false;
            }
            if(type == 'edit'){
                $.ajax({
                    url:"/index.php/?m=admin&c=goods&a=edit",
                    type:'post',
                    data:{price:price,name:name,category_id:category_id,status:status,sort:sort,keyword:keyword,brief:brief,id:id},
                    dataType:'json',
                    success:function(data){
        
                        if(data.status ==0){
                            // layer.msg(data.info);
                        }else{
                            // layer.msg(data.info);
                        //     setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
                        //         // location.href=data.url;
						// },1000);
                        }
                    }
			    })	
            }else if(type == 'add'){
                $.ajax({
                    url:"/index.php/?m=admin&c=goods&a=add",
                    type:'post',
                    data:{price:price,name:name,category_id:category_id,status:status,sort:sort,keyword:keyword,brief:brief},
                    dataType:'json',
                    success:function(data){
        
                        if(data.status ==0){
                            layer.msg(data.info);
                        }else{
                            layer.msg(data.info);
                        }
                    }
			    })	
            }
            
            
        }



        // var selectedItem = <?php echo $_list['selectedItem'] ? $_list['selectedItem'] : '[]'; ?> ;
        // var tempUrl = "<?php echo U('Goods/Goods/search_spec');?>";
        // var getmodelurl = "<?php echo U('Goods/ProductModel/ajax_get_model')?>";
        // var getmodelinfourl = "<?php echo U('Goods/ProductModel/ajax_get_model_info?goods_id='.$_list['id'].'')?>";
        // var IMG_PATH = "<?php echo IMG_PATH;?>";
        // /**
        //  *初始化
        //  */
        // $(function() {
        //     //默认高亮
        //     $(window.parent.document).find(".z_side").removeClass("hover");
        //     $(window.parent.document).find(".n11").addClass("hover");
        //     //切换
        //     var tabTitle = ".tabs dt a";
        //     var tabContent = ".tabs dd";
        //     $(tabTitle + ":first").addClass("hover");
        //     $(tabContent).not(":first").hide();
        //     $(tabTitle).unbind("click").bind("click", function() {
        //         $(this).siblings("a").removeClass("hover").end().addClass("hover");
        //         var index = $(tabTitle).index($(this));
        //         $(tabContent).eq(index).siblings(tabContent).hide().end().fadeIn(0);
        //     });
        //     //初始化分类选择
        //     JsonCategory = <?php echo json_encode($this -> tree) ?> ;
        //     nb_category(0, '.root');
            
        //     //初始化模型
        //     <?php if($_list['model']):?>
        //         $('#model').val('<?php echo $_list['model']?>').change();
        //         //选中值
        //         var selmodel = <?php echo json_encode($selmode)?>;              
        //     <?php endif;?>
        // })
        // $(function(){
        //     var tabTitle = ".tabs dt a";
        //     var tabContent = ".tabs dd";
        //     $(tabTitle+":last").one("click",function(){
        // $.getScript("<?php echo JS_PATH;?>image-upload/upload.js");
        // });
        // })
        // //默认货号
        // var defaultProductNo = "<?php echo C('site_numprefix').time().rand(10,99)?>";
        // $(function() {
        //     initProductTable();
        //     //存在商品信息
        //     <?php   if (isset($_list)): ?>
        //         <?php
        //         // $_list['small_pics']=array_unique($_list['small_pics']);
        //         // $_list['thumb_pics']=array_unique($_list['thumb_pics']);
        //         ?>
        //         var goods = <?php echo json_encode($_list) ?> ;
        //         var goodsRowHtml = template('goodsRowTemplate', {'templateData': [goods]});
        //         $('#goodsBaseBody').html(goodsRowHtml);
        //         $('[name="_goods_barcode[0]"]').val(goods.barcode);
        //         $('[name="_goods_sn[0]"]').val(goods.sn);
        //         $('[name="_goods_number[0]"]').val(goods.goods_number);
        //         $('[name="_shop_price[0]"]').val(goods.shop_price);
        //         $('[name="_market_price[0]"]').val(goods.market_price);
        //         $('[name="_cost_price[0]"]').val(goods.cost_price); 
        //         <?php   if (!empty($_list['thumb'])): ?>
        //             $('.upimg').next("span").html("<img src=" + goods.thumb + " height=43>"); 
        //         <?php endif ?>
        //         <?php   if (!empty($_list['pics'])): ?>
        //             for (data in goods.pics) {
        //                 $('.filelist ').append('<li style="border: 1px solid rgb(59, 114, 165)" order="100"><input type="hidden" name="goodsphoto[]" value="' + goods.pics[data] + '"><img width="152" height="152" alt="" src="' + goods.pics[data] + '"><span class="setdef">默认</span><span class="setdel">删除</span></li>');
        //             } 
        //         <?php endif ?>
        //         <?php   if (!empty($_list['small_pics'])): ?>
        //             for (data in goods.pics) {
        //                 $('.filelist li').eq(data).append('<input type="hidden" name="small_pics[]" value="'+goods.small_pics[data]+'">');
        //             } 
        //         <?php endif ?>
        //          <?php   if (!empty($_list['thumb'])): ?>
        //             for (data in goods.pics) {
        //                 $('.filelist li').eq(data).append('<input type="hidden" name="thumb[]" value="'+goods.thumb_pics[data]+'">');
        //             } 
        //         <?php endif ?>
        //     <?php   else : ?>
        //         $('[name="_goods_sn[0]"]').val(defaultProductNo); 
        //     <?php endif ?>
        //     //存在货品信息,进行数据填充
        //     <?php if (isset($product)): ?>
        //         var spec_array = <?php echo json_encode($product[0]['spec_array']) ?> ;
        //         var product = <?php echo json_encode($product) ?> ;
        //         var goodsHeadHtml = template('goodsHeadTemplate', {'templateData': spec_array});
        //         $('#goodsBaseHead').html(goodsHeadHtml);
        //         var goodsRowHtml = template('goodsRowTemplate', {'templateData': product});
        //         $('#goodsBaseBody').html(goodsRowHtml); 
        //     <?php endif ?>
        // });
        // //初始化货品表格
        // function initProductTable() {
        //     //默认产生一条商品标题空挡
        //     var goodsHeadHtml = template('goodsHeadTemplate', {'templateData': []});
        //     $('#goodsBaseHead').html(goodsHeadHtml);
        //     //默认产生一条商品空挡
        //     var goodsRowHtml = template('goodsRowTemplate', {'templateData': [[]]});
        //     $('#goodsBaseBody').html(goodsRowHtml);
        // }
        // // 表单 验证
        // $(function() {
        //     $.Tipmsg.r = null;
        //     var demo = $(".goodsForm").Validform({
        //         btnSubmit: "#btn_sub",
        //         btnReset: ".btn_reset",
        //         label: ".label",
        //         showAllError: false,
        //         //ajaxPost: true,
        //         tiptype: function(msg, o, ctrl) {
        //             var e = o.obj.context.name;
        //             if (e.length > 1) {
        //                 if (e == 'name') {
        //                     $(".tabs dt a").eq(0).click();
        //                 } else {
        //                     $(".tabs dt a").eq(1).click();
        //                 }
        //             }
        //             // if (o.type==3){
        //             //     art.dialog({id:'tip',width: 320, time: 5, title: '温馨提示(5秒后关闭)', content: msg, ok: true});
        //             // }
        //         },
        //         beforeCheck: function(curform) {

        //             var cat_ids =$('.select option:selected').val();
        //             console.log(cat_ids);
        //             // var cat_ids = $("input[name='cat_ids[]']");
        //             if (cat_ids.length == 0) {
        //                 $(".tabs dt a").eq(0).click();
        //                 alert('请选择商品分类');
        //                 return false;
        //             }
        //             //editor.sync("#content");
        //         },
        //         beforeSubmit:function(curform){
        //             /*
        //              * 将商品规格属于序列化后传递 避免提交input超限
        //              * 2015-09-16 16:31:11 @李春林
        //              */
        //             var _goods_barcode = $('[name^="_goods_barcode"]').serialize();
        //             $('[name^="_goods_barcode"]').remove();
        //             $(curform).append('<input type="hidden" name="_goods_barcode" value="'+_goods_barcode+'">');
                    
        //             var _goods_sn = $('[name^="_goods_sn"]').serialize();
        //             $('[name^="_goods_sn"]').remove();
        //             $(curform).append('<input type="hidden" name="_goods_sn" value="'+_goods_sn+'">');
                    
        //             var _spec_array = $('[name^="_spec_array"]').serialize();
        //             $('[name^="_spec_array"]').remove();
        //             $(curform).append('<input type="hidden" name="_spec_array" value="'+_spec_array+'">');
                    
        //             var _goods_number = $('[name^="_goods_number"]').serialize();
        //             $('[name^="_goods_number"]').remove();
        //             $(curform).append('<input type="hidden" name="_goods_number" value="'+_goods_number+'">');
                    
        //             var _shop_price = $('[name^="_shop_price"]').serialize();
        //             $('[name^="_shop_price"]').remove();
        //             $(curform).append('<input type="hidden" name="_shop_price" value="'+_shop_price+'">');
                    
        //             var _market_price = $('[name^="_market_price"]').serialize();
        //             $('[name^="_market_price"]').remove();
        //             $(curform).append('<input type="hidden" name="_market_price" value="'+_market_price+'">');
                    
        //             var _cost_price = $('[name^="_cost_price"]').serialize();
        //             $('[name^="_cost_price"]').remove();
        //             $(curform).append('<input type="hidden" name="_cost_price" value="'+_cost_price+'">');
                    
        //             var _products_ids = $('[name^="_products_ids"]').serialize();
        //             $('[name^="_products_ids"]').remove();
        //             $(curform).append('<input type="hidden" name="_products_ids" value="'+_products_ids+'">');
        //             art.dialog({id:'tip',width: 320, title: false, cancel: false,fixed: true,lock: true, content:'正在保存数据,请勿刷新！'});
        //         },
        //         callback: function(data) {
        //             $("#Validform_msg").hide();
        //             if (data.status == 0) {
        //                 art.dialog({
        //                     id: 'tip',
        //                     width: 320,
        //                     time: 5,
        //                     title: '温馨提示(5秒后关闭)',
        //                     content: data.info,
        //                     ok: true
        //                 });
        //             }
        //             if (data.status == 1) {
        //                 window.location.href = data.url;
        //             }
        //         }
        //     });
        // });
        // //批量修改信息
        // $('.change_all_goods').click(function(){
        //     art.dialog({
        //         padding: '0px ',
        //         id: 'BatchEditingMoney',
        //         background: '#ddd',
        //         opacity: 0.3,
        //         title: '批量编辑商品信息',
        //         content: document.getElementById('batcheditGoods'),
        //         ok:function() {
        //             _goods_number_change    = $('[name="_goods_number_change"]').val();
        //             _shop_price_change      = $('[name="_shop_price_change"]').val();
        //             _market_price_change    = $('[name="_market_price_change"]').val();
        //             _cost_price_change      = $('[name="_cost_price_change"]').val();
        //             var num_reg = /^[-\+]?\d*$/;
        //             var price_reg = /^[-\+]?\d+(\.\d{2})?$/;
        //             if(!(num_reg.test(_goods_number_change)) || !(price_reg.test(_shop_price_change)) || !(price_reg.test(_market_price_change)) || !(price_reg.test(_cost_price_change))){
        //                 alert('请输入正确的数字!');
        //                 return false;
        //             }
        //             //库存
        //             $('#goodsBaseBody [name^="_goods_number"]').each(function(index,data){
        //                 num = parseInt($(this).val()) + parseInt(_goods_number_change);
        //                 num = num < 0 ? 0 : num;
        //                 $(this).val(num);
        //             })
        //             //销售价
        //             $('#goodsBaseBody [name^="_shop_price"]').each(function(index,data){
        //                 num = Number($(this).val()) + Number(_shop_price_change);
        //                 num = num < 0 ? 0 : num;
        //                 $(this).val(num.toFixed(2));
        //             })
        //             //市场价
        //             $('#goodsBaseBody [name^="_market_price"]').each(function(index,data){
        //                 num = Number($(this).val()) + Number(_market_price_change);
        //                 num = num < 0 ? 0 : num;
        //                 $(this).val(num.toFixed(2));
        //             })
        //             //成本
        //             $('#goodsBaseBody [name^="_cost_price"]').each(function(index,data){
        //                 num = Number($(this).val()) + Number(_cost_price_change);
        //                 num = num < 0 ? 0 : num;
        //                 $(this).val(num.toFixed(2));
        //             })
        //             $('[name="_goods_number_change"]').val('+0');
        //             $('[name="_shop_price_change"]').val('+0.00');
        //             $('[name="_market_price_change"]').val('+0.00');
        //             $('[name="_cost_price_change"]').val('+0.00');
        //             return true;
        //         },
        //         cancel:true
        //     });
        // });
        // // 全选
        // $(window).load(function(){
        //     $('#select_all').on('click',"input",function() {
        //         if ($(this).is(':checked') == true) {
        //             $("input[name='checked_id']").each(function() {
        //                 $(this).attr("checked",true);
        //             });
        //         } else {
        //             $("input[name='checked_id']").each(function() {
        //                 $(this).attr("checked",false);
        //             });
        //         }                
        //     });
        //     $("input[name='checked_id']").click(function() {
        //         if($(this).attr("checked")){
        //             $(this).attr("checked","true");
        //         }else{
        //             $(this).removeAttr("checked");
        //         }
        //         var num= 0;
        //         $("input[name='checked_id']").each(function() {
        //             if($(this).attr("checked")){
        //                 num++;
        //             }
        //         });
        //         if(num==$("input[name='checked_id']").length){
        //             $('#select_all').children('input').attr("checked","true");
        //         }else{
        //             $('#select_all').children('input').removeAttr("checked");
        //         }
        //     });
        // })
    </script>
</body>
</html>